#include <bits/stdc++.h>
using namespace std;
int d[100000],a[100000],v[100000];
int tot[100000];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int ans=0;
        int n,m,l,V;
        cin>>n>>m>>l>>V;
        for(int j=1;j<=n;j++)
        {
                cin>>d[j]>>v[j]>>a[j];
        }
        for(int j=1;j<=m;j++)
        {
            cin>>tot[i];
        }
        for(int j=1;j<=n;j++)
        {
            if(a[i]==0)
            {
                if(v[i]<=V) ans++;
            }
        }
        cout<<n-ans<<" "<<n-ans<<endl;
    }

}
